package com.gxa.excption;

import com.gxa.common.R.ResponseData;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;
import java.sql.SQLException;

@RestControllerAdvice
public class ExceptionHandlerAdviceController {

    @ExceptionHandler(IncorrectCredentialsException.class)
    @ResponseBody
    public ResponseData incorrectCredentialsException(){
        ResponseData r = new ResponseData();
        r.setCode(500);
        r.setMsg("用户名或密码错误");
        return r;
    }

    @ExceptionHandler(UnknownAccountException.class)
    @ResponseBody
    public ResponseData unknownAccountException(){
        ResponseData r = new ResponseData();
        r.setCode(500);
        r.setMsg("用户名或密码错误");
        return r;
    }

    @ExceptionHandler(IOException.class)
    @ResponseBody
    public ResponseData iOException(){
        ResponseData r = new ResponseData();
        r.setCode(500);
        r.setMsg("iOException");
        return r;
    }

//    @ExceptionHandler(SQLException.class)
    @ResponseBody
    public ResponseData sqlException(){
        ResponseData r = new ResponseData();
        r.setCode(500);
        r.setMsg("sqlException");
        return r;
    }
}
